import { ref } from 'vue'
import { defineStore } from 'pinia'
import { loginAPI } from '@/apis/user'
export const useUserStore = defineStore(
  'user',
  () => {
    // 定义管理用户的state
    const userInfo = ref({})
    //action获取用户数的caction函数
    const getUserInfo = async ({ account, password }) => {
      const res = await loginAPI({ account, password })
      userInfo.value = res.result
    }
    //退出时清除用户信息
    const cleanUserInfo = () => {
      userInfo.value = {}
    }
    //以对象的形式将state和action返回
    return { userInfo, getUserInfo, cleanUserInfo }
  },
  {
    persist: true
  }
)
